#ifndef TIMER_H
#define TIMER_H

#include <InterruptServiceRoutine.h>
#include <Resource.h>

namespace Timer_IF
{
  const int getTick =0;
}

/**
  Handles setting up and interrupts by the programmable interrupt timer (PIT)
**/
class Timer : public InterruptServiceRoutine
{
public:
  Timer();

  ~Timer();
  
  /**
    Sets up the timer to interrupt at 'frequency' Hertz.
  **/
  void init(u32int freq);

  /**
    The virtual function that handles the timer interrupt.
  **/
  virtual void run(Registers *r);

  /**
    Retrieves the current time.
  **/
  u32int getTick()
  {
    return tick;
  }

  /**
    We are a system resource.
  **/
  Resource *resource;

private:
  
  /**
    The frequency interrupts are taking place
  **/
  u32int frequency;
  
  /**
    The phase (wavelength) of each interrupt in ms (1000 / frequency) 
  **/
  u32int phase;

  /**
    The current time.
  **/
  u32int tick;

};

#endif
